package edu.lingnan.mapper;

import edu.lingnan.pojo.ShoppingCart;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Entity edu.lingnan.pojo.ShoppingCart
 */
@Mapper
public interface ShoppingCartMapper extends BaseMapper<ShoppingCart> {

    //通过用户id和商品id查询
    @Select("select * from shopping_cart where product_id = #{productId} and user_id=#{userId}")
    List<ShoppingCart> selectShoppingCartByUserIdAndProductId(ShoppingCart shoppingCart);

    //加入购物车
    @Insert("insert into shopping_cart values (#{userId},#{productId},#{productNumber},#{amount})")
    void addShoppingCart(ShoppingCart shoppingCart);

    //修改商品数量
    @Update("update shopping_cart set product_number =product_number+#{productNumber} where product_id = #{productId} and user_id=#{userId} ")
    void increaseProductNumber(ShoppingCart shoppingCart);

    //通过用户id查找商品
    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> selectShoppingCartByUserId(Long userId);

    //删除用户的指定商品
    @Delete("delete from shopping_cart where product_id = #{productId} and user_id=#{userId}")
    int deleteMyProduct(ShoppingCart shoppingCart);
}




